{include file="public/header" /}
<body class="gray-bg">
<div class="layui-fluid layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-header">编辑用户</div>
        <div class="layui-card-body layui-form">
            <div class="layui-row layui-col-space10 layui-form-item ">
                <input type="hidden" name="u_id" value="{$vip.u_id}">
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="nick_name" value="{$vip.nick_name}" lay-verify="required|username" placeholder="用户名" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">头像</label>
                    <input type="hidden" name="head_img" id="lay-img" value="{$vip.head_img}" lay-verify="image">
                    <div class="layui-input-block">
                        <div id="lay-upload">上传头像</div>
                        <div class="layui-upload-list" id="lay-img-list">
                            <img class="layui-circle layui-head-img" style="margin-left: 0px;" src="{$vip.head_img}" onerror="this.src='/static/admin/images/head_default.gif'"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="pwd_code" value="{$vip.pwd_code}">
                        <input type="password" name="password" lay-verify="pass" placeholder="不修改请留空" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" value="{$vip.phone}" lay-verify="required" placeholder="手机号" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" value="{$vip.email}" lay-verify="required" placeholder="邮箱" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">个性签名</label>
                    <div class="layui-input-block">
                        <input type="text" name="signature" value="{$vip.signature}" placeholder="个性签名" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="1" title="男" {if condition="$vip['sex'] == 1"}  checked {/if}>
                        <input type="radio" name="sex" value="0" title="女" {if condition="$vip['sex'] == 0"}  checked {/if}>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_lock" value="1" title="未锁定" {if condition="$vip['is_lock'] == 1"}  checked {/if}>
                        <input type="radio" name="is_lock" value="2" title="已锁定" {if condition="$vip['is_lock'] == 2"}  checked {/if}>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                        </button>
                        <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    // 图片上传
    if("{$configState}" == 0){
        wk.uploadImg({size:2,type:'jpg,jpeg,png',url:"{:url('Upload/upload')}",domain:"{:config('DOMAIN')}",sort:'',head:1});
    }else {
        wk.uploadImg({size:2,type:'jpg,jpeg,png',url:"{:url('admin/upload/uploadLocality')}",sort:'',head:1});
    }

    layui.use(['form','element'], function() {
        var form = layui.form
            , element = layui.element

        form.verify({
            image:[/\S/,'请上传头像'],
            username:function(value,item){
                if(!/^[\S]{2,10}$/.test(value)){
                    return '名称必须2到10字符，且不能出现空格';
                }
                var checkResult = "";
                $.ajax({
                    url:"{:url('Vip/checkName')}",
                    type:'post',
                    data:"nick_name="+value +'&id='+ $('input[name=u_id]').val(),
                    async: false,//必须同步
                    success:function(res){
                        if(res.code == 100){
                            checkResult = "该名称已存在";
                        }
                    }
                })
                return checkResult;
            }
            ,pass:function(value,item){
                if(value != "" && !/^[\S]{6,16}$/.test(value)){
                    return '密码必须6到16位，且不能出现空格';
                }
            }
        });

        form.on('submit(component-form-element)', function (data) {
            // $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('edit_vip')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            setTimeout(function () {
                                wk.layer_close();
                                window.location.href="{:url('Vip/index')}";
                            },100);
                        })
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>